package tech.aistar.corejava.day12.homework.home03;

import java.util.Iterator;
import java.util.List;

/**
 * @Author: lya
 * @Description: 本类的作用描述:
 * @CreateDate: 2019/7/30
 * @Version: 1.0
 */
public class TestProduct {
    public static void main(String[] args) {
        IProductDao productDao = new ProductDaoImlp();

        Product p1 = new Product(1,"洗手粉",18.5,"中国");
        Product p2 = new Product(2,"肥皂",4.5,"中国");
        Product p3 = new Product(3,"牙膏",32.5,"中国");
        Product p4 = new Product(4,"毛巾",14.5,"中国");
        Product p5 = new Product(5,"洗面奶",26.0,"中国");

        //添加5个商品对象
        productDao.add(p1);
        productDao.add(p2);
        productDao.add(p3);
        productDao.add(p4);
        productDao.add(p5);

        //获取第3个商品对象
        productDao.select(3);

        //删除第2个商品对象
        productDao.delete(2);

        //将第3个商品对象的价格改为原来的1.5倍
        productDao.update(3,1.5);


        //迭代器遍历该集合中的所有商品对象
        List<Product> list = productDao.findAll();

        Iterator<Product> iter = list.iterator();
        while(iter.hasNext()){
            Product p = iter.next();
            System.out.println(p);
        }

        System.out.println("======================");
        //使用foreach遍历该集合中的所有商品对象
        list.forEach(System.out::println);

        //System.out.println(productDao.findAll());

    }
}
